package com.meta.platform.contract.core.repository.impl;

import com.meta.framework.common.utils.SecurityUtils;
import com.meta.platform.contract.core.mapper.ContractPlanFundMapper;
import com.meta.platform.contract.domain.aggr.ContractPlanFundDo;
import com.meta.platform.contract.domain.tunnel.db.ContractPlanFundRepository;
import com.meta.platform.contract.intf.entity.ContractPlanFund;
import com.meta.platform.contract.intf.ro.ContractPlanFundRo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 合同计划回款
 *
 * @Title: ContractPlanFundRepositoryImpl
 * @Author: M.simple
 * @Remark: The modified content
 * @CreateDate: 2020-12-08 15:53:37
 * @Version: v2.0
 */
@Service
public class ContractPlanFundRepositoryImpl implements ContractPlanFundRepository {

    @Autowired
    private ContractPlanFundMapper contractPlanFundMapper;

    /**
     * insert contractPlanFund info
     *
     * @param contractPlanFund:
     * @return void
     * @method insertContractPlanFund
     * @author M.simple
     * @date 2020-12-08 15:53:37
     */
    @Override
    public void insertContractPlanFund(ContractPlanFund contractPlanFund) {
        contractPlanFund.setCreateBy(SecurityUtils.getUserId());
        contractPlanFund.setUpdateBy(SecurityUtils.getUserId());
        contractPlanFundMapper.insertContractPlanFund(contractPlanFund);
    }

    /**
     * batch insert contractPlanFund info
     *
     * @param contractPlanFunds:
     * @return void
     * @method insertContractPlanFund
     * @author M.simple
     * @date 2020-12-08 15:53:37
     */
    @Override
    public void batchInsertContractPlanFund(List<ContractPlanFund> contractPlanFunds) {
        contractPlanFundMapper.batchInsertContractPlanFund(contractPlanFunds);
    }

    /**
     * update contractPlanFund info
     *
     * @param contractPlanFund:
     * @return int
     * @method updateContractPlanFund
     * @author M.simple
     * @date 2020-12-08 15:53:37
     */
    @Override
    public int updateContractPlanFund(ContractPlanFund contractPlanFund) {
        contractPlanFund.setUpdateBy(SecurityUtils.getUserId());
        return contractPlanFundMapper.updateContractPlanFund(contractPlanFund);
    }

    /**
     * update contractPlanFund info by Pk
     *
     * @param contractPlanFund:
     * @return int
     * @method updateContractPlanFundByPk
     * @author M.simple
     * @date 2020-12-08 15:53:37
     */
    @Override
    public int updateContractPlanFundByPk(ContractPlanFund contractPlanFund) {
        contractPlanFund.setUpdateBy(SecurityUtils.getUserId());
        return contractPlanFundMapper.updateContractPlanFundByPk(contractPlanFund);
    }

    /**
     * list contractPlanFund info
     *
     * @param contractPlanFund:
     * @return List<ContractPlanFund>
     * @method listContractPlanFund
     * @author M.simple
     * @date 2020-12-08 15:53:37
     */
    @Override
    public List<ContractPlanFund> listContractPlanFund(ContractPlanFundRo contractPlanFund) {
        return contractPlanFundMapper.listContractPlanFund(contractPlanFund);
    }

	@Override
	public ContractPlanFundDo getById(Long id) {
        if (id == null){
            return null;
        }
		ContractPlanFundRo ro = new ContractPlanFundRo();
		ro.setId(id);
		return ContractPlanFundDo.of(contractPlanFundMapper.listContractPlanFund(ro).get(0));
	}
}
